* Reset settings and initialize log file
launch, path("share/vacation")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Show the prevalence of summer vacation of age of youngest child.
*-------------------------------------------------------------------------------


if "$estimate" != "0" {
	* Load our estimation sample
	gzuse "$basepath/data/derived/cps_bms_sample.dta.gz", clear

	* Restrict to years in which wkstat and whyabsnt are consistently coded
	keep if year >= 1994
	assert missing(whyabsnt) == (absent == 0)

	* Retain variables we need
	keep pid tm month wtfinl tmspline* weeks female youngest absent whyabsnt

	* Tag absence due to vacation
	gen byte vacation = (whyabsnt == 5)

	* Aggregate across household types
	gcollapse (mean) vacation (first) month tmspline* weeks (rawsum) wtfinl [pw = wtfinl], by(female youngest tm)
	tempfile core
	save `core'

	* Loop over sex
	foreach f of numlist 0 1 {
		* Loop over presence/age of youngest child
		foreach k of numlist 0 1 2 3 {
			* Reload the data
			use if female == `f' & youngest == `k' using `core', clear
			quietly tsset tm

			* Estimate seasonal movements in vacation-taking
			quietly ivreg2 vacation ib5.month tmspline* weeks [aw = wtfinl], bw($bandwidth) robust small
			process_estimates, path("vacation") model("f`f'_k`k'")
		}
	}
}


* Prepare estimates
*-------------------------------------------------------------------------------

* Load estimates into memory
load_estimates, path("vacation")

* Prepare coefficient labels for each month
make_coeflabels


* Plot seasonality in vacation-taking by sex and age of youngest child
*-------------------------------------------------------------------------------

* Prepare background shading
clear
set obs 14
gen rlow = -1
gen rupp = 7
gen rval = _n - 0.5

* Plot estimates
foreach f of numlist 0 1 {
	if `f' == 0 local flbl "Men"
	if `f' == 1 local flbl "Women"

	#delimit ;
	coefplot
		(f`f'_k0, offset(-.075) recast(connected) label("No child < 18"))
		(f`f'_k1, offset(-.025) recast(connected) label("Youngest child < 6"))
		(f`f'_k2, offset(+.025) recast(connected) label("Youngest child 6-12"))
		(f`f'_k3, offset(+.075) recast(connected) label("Youngest child 13-17")),
		coeflabels(`coeflabels')
		title("{bf:`flbl'}")
		xtitle("")
		xlabel(, alternate)
		ytitle("")
		yscale(range(-1 7))
		ylabel(-1(1)7)
		addplot(
			rarea rupp rlow rval if inrange(rval, 0.5, 5.5), color($ltgs) plotregion(margin(t=0 b=0)) below ||
			scatteri 0 0.5 0 13.5, recast(line) color(black) below)
		vertical
		rescale(100)
		legend(size(*0.75) rows(2) order(4 6 8 10));
	#delimit cr

	tempfile g`f'
	graph save "`g`f''"
}

grc1leg "`g1'" "`g0'", l1title("      Difference relative to May (p.p.)", size(*0.75))
nicepdf "$basepath/output/vacation.pdf", panels(2) indirect replace

* Close the log file
unlaunch
